<?php

header("Content-type: text/html; charset=utf-8");     


function C($key='')
{
	$configs = include '../config.php';

	if($key && array_key_exists($key, $configs)){
		return $configs[$key];
	}else{
		return $configs;
	}
}
function D($data)
{
	var_dump($data);
}

/**
 * 递归地查找多维数组中的值
 * @Author   F
 * @DateTime 2018-01-22T00:26:14+0800
 * @param    [type]                   $value [description]
 * @param    [type]                   $array [description]
 * @return   [type]                          [description]
 */
function deep_in_array($value, $array) {   
    foreach($array as $item) {   
        if(!is_array($item)) {   
            if ($item == $value) {  
                return true;  
            } else {  
                continue;   
            }  
        } else{
        	if(deep_in_array($value, $item)){  
            	return true;
            }      
        }  
        // if(in_array($value, $item)) {  
        //     return true;      
        // } else if(deep_in_array($value, $item)) {  
        //     return true;      
        // }  
    }   
    return false;   
}

function deep_array_count_values($value, $array) {
	$n=0;   
    foreach($array as $item) {   
        if(!is_array($item)) {   
            if ($item == $value) {  
                $n++; 
            } else {  
                continue;   
            }  
        } else{
        	$n+=deep_array_count_values($value, $item);    
        }   
    }   
    return $n;   
}


/**
 * 多维数组查找
 * @Author   F
 * @DateTime 2018-01-22T01:01:09+0800
 * @param    [type]                   $elem  [description]
 * @param    [type]                   $array [description]
 * @return   [type]                          [description]
 */
function in_multiarray($elem, $array)
    {
        $top = sizeof($array) - 1;
        $bottom = 0;
        while($bottom <= $top)
        {
            if($array[$bottom] == $elem)
                return true;
            else
                if(is_array($array[$bottom]))
                    if(in_multiarray($elem, ($array[$bottom])))
                        return true;
                   
            $bottom++;
        }       
        return false;
    }

/**
 * [Ftime 实现时间转换]
 * @Author   Xuebingsi
 * @DateTime 2018-01-10T08:38:34+0800
 * @param    [int]                   $time [时间戳]
 */
function Ftime($time)
{
	$now = time();

	$diff = $now-$time;

	if($diff<60){
		return "刚刚";
	}elseif($diff<3600){
		return ceil($diff/60)."分钟前";
	}elseif($diff<86400){
		return ceil($diff/3600)."小时前";
	}elseif($diff<(86400*7)){
		return ceil($diff/86400)."天前";
	}else{
		return date("Y-m-d H:i:m",$time);
	}
}

function diffDate($date1,$date2)
{
	$dataTime1 = strtotime($date1);
	$dataTime2 = strtotime($date2);

	$diff = abs($dataTime1-$dataTime2);

	return $diff/86400;
}
/**
 * [getRand description]
 * @Author   Xuebingsi
 * @DateTime 2018-01-10T09:16:35+0800
 * @param    integer                  $num [description]
 * @return   [type]                        [description]
 */
function getRand($num=4)
{
	$str ='';

	for ($i=0; $i <$num ; $i++) { 
		$str .= mt_rand(0,9);
	}

	return $str;
}
/**
 * [getWeekDay description]
 * @Author   Xuebingsi
 * @DateTime 2018-01-10T09:11:55+0800
 * @param    string                   $date [description]
 * @return   [type]                         [description]
 */
function getWeekDay($date='')
{
	if(empty($date)){
		$time = time();
	}else{
		$time = strtotime($date);
	}

	$dateDetail = getdate($time);

	return $dateDetail['weekday'];
}




function Fdb($bit)
{
	if($bit<1024){
		return $bit."b";
	}elseif($bit<pow(1024, 2)){
		return round($bit/1024,2)."kb";
	}elseif($bit<pow(1024, 3)){
		return round($bit/pow(1024, 2),2)."mb";
	}elseif($bit<pow(1024, 4)){
		return round($bit/pow(1024, 3),2)."gb";
	}elseif($bit<pow(1024, 5)){
		return round($bit/pow(1024, 4),2)."tb";
	}
}






 ?>